package cn.niit.smbms.exception;

import cn.niit.smbms.model.reponse.BaseResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

/**
 * @author xiaomi
 */
@RestControllerAdvice
public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value = ArithmeticException.class)
    public BaseResponse handlerArithmeticException(ArithmeticException e){
        return  new BaseResponse("404", "您访问的页面不存在！");
    }

    @ResponseBody
    @ResponseStatus(HttpStatus.BAD_GATEWAY)
    @ExceptionHandler(value = CustomException.class)
    public BaseResponse handlerCustomException(CustomException e){
        return  new BaseResponse("502", "程序发生错误，请联系管理员！");
    }

    @ResponseBody
    @ExceptionHandler(value = RuntimeException.class)
    public BaseResponse handlerRuntiemException(RuntimeException e){
        return  new BaseResponse("500", "程序出现异常，请稍后再试！");
    }
}
